<html>
<head><meta charset="utf-8"><title>ItemTree · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html">ItemTree</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="201004031"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201004031" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201004031">(Jun 16 2020 at 12:00)</a>:</h4>
<p>I've resurrected the stubs/item tree work and moved the def collector over to it (removing raw items completely). Now I'm looking into replacing queries such as <code>generic_params</code> and <code>impl_data</code>, but they're keyed off of <code>GenericDefId</code> and <code>ImplId</code>, which are just interned IDs that return an AST node, and I can't query the item tree with that.</p>
<p>Not sure about the best way forward here, but I'm feeling like the additional queries should be removed entirely and all callers be moved over to use the item tree directly. Does that make sense?</p>



<a name="201005930"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201005930" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201005930">(Jun 16 2020 at 12:19)</a>:</h4>
<p>Yup!</p>



<a name="201006040"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201006040" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201006040">(Jun 16 2020 at 12:20)</a>:</h4>
<p>That is, the ID I think should contain (id of parent, index in the item tree). Well, super long-term I imagine we might want (id of parent, name of child, diambiguator), but we can get away without it for the time being</p>



<a name="201006296"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201006296" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201006296">(Jun 16 2020 at 12:23)</a>:</h4>
<p>Do you mean the parent item or file? <code>FileId</code> would be easier for now</p>



<a name="201006599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201006599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201006599">(Jun 16 2020 at 12:26)</a>:</h4>
<p>Ideally, it should be parent item I think</p>



<a name="201006613"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201006613" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201006613">(Jun 16 2020 at 12:26)</a>:</h4>
<p>We already track this actually</p>



<a name="201006630"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201006630" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201006630">(Jun 16 2020 at 12:26)</a>:</h4>
<div class="codehilite"><pre><span></span><code>#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ItemLoc&lt;N: AstNode&gt; {
    pub container: ContainerId, // &lt;- this is the parent
    pub ast_id: AstId&lt;N&gt;,
}
</code></pre></div>



<a name="201006708"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201006708" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201006708">(Jun 16 2020 at 12:27)</a>:</h4>
<p>So, we should replace <code>AstId</code> with <code>ItemTreeId</code>. Note that that'll require some significant changes to <code>get source of the thing</code> infrastructure</p>



<a name="201007718"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201007718" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201007718">(Jun 16 2020 at 12:37)</a>:</h4>
<p><span class="user-mention" data-user-id="211727">@Jonas Schievink</span> it might make sense to take a look at the <a href="http://source_to_def.rs">source_to_def.rs</a> file</p>



<a name="201007742"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201007742" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201007742">(Jun 16 2020 at 12:37)</a>:</h4>
<p>It contains a bit of IDE specific magic which affects how we setup ids and sources</p>



<a name="201007766"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201007766" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201007766">(Jun 16 2020 at 12:37)</a>:</h4>
<p>Curiously, this is exactly the same pattern that is used in Roslyn and Kotlin (and I really should blog about it)...</p>



<a name="201007905"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201007905" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201007905">(Jun 16 2020 at 12:39)</a>:</h4>
<p>The core idea is that, if you have an <code>ast::Thing</code>, and want a <code>hir::Thing</code>, you look at the ast parent, recursively get <code>hir::ParentThing</code>, and then look through hir parent's children to find the child whose source is <code>ast::Thing</code>. That is, in a sense a lookup is reversed.</p>



<a name="201136094"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201136094" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201136094">(Jun 17 2020 at 12:52)</a>:</h4>
<p>I did not realize this would be such a huge undertaking <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="201136146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201136146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201136146">(Jun 17 2020 at 12:53)</a>:</h4>
<p>Well, you are about half-way in, so at this point it's easier just to finish the thing :)</p>



<a name="201136196"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201136196" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201136196">(Jun 17 2020 at 12:53)</a>:</h4>
<p>But yeah, I feel like we've lost a significant amount of experemination freedom we had initially, when such refactorings were relatively straightforward...</p>



<a name="201136214"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201136214" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201136214">(Jun 17 2020 at 12:53)</a>:</h4>
<p>Any good idea for how to handle/represent inner items in the item tree? Since they might be nested in inner blocks, just having a <code>Vec&lt;ModItem&gt;</code> in <code>Function</code> might not cut it.</p>



<a name="201136310"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201136310" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201136310">(Jun 17 2020 at 12:54)</a>:</h4>
<p>(Body lowering and the item data queries create item IDs from AST nodes, which now doesn't work anymore, so I have to fix that)</p>



<a name="201136471"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201136471" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201136471">(Jun 17 2020 at 12:56)</a>:</h4>
<p>Hmm, since the item data queries return fully expanded data, how do we map that to the item tree? Maybe we need to keep the queries and have them still perform the expansion?</p>



<a name="201136528"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201136528" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201136528">(Jun 17 2020 at 12:56)</a>:</h4>
<p>Those are good questions....</p>



<a name="201136752"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201136752" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201136752">(Jun 17 2020 at 12:58)</a>:</h4>
<p>For inner items, I see two approaches:</p>
<ul>
<li>we store <em>all</em> items in the item tree, and the same <code>ItemLoc</code> approach works. It's just <code>function</code> and other expression-owning things can be containers now.</li>
<li>we store only top-level items in the item tree, but then have a separate query for inner items (which should allow us to parse bodies lazily)</li>
</ul>



<a name="201136868"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201136868" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201136868">(Jun 17 2020 at 12:59)</a>:</h4>
<blockquote>
<p>Since they might be nested in inner blocks, just having a Vec&lt;ModItem&gt; in Function might not cut it.</p>
</blockquote>
<p>We might still attach all items to the parent item, or we can have an ID of the block. Not sure which one is better</p>



<a name="201137318"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201137318" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201137318">(Jun 17 2020 at 13:03)</a>:</h4>
<p>we certainly should still do expansion of item bodies lazily, right?</p>



<a name="201137593"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201137593" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201137593">(Jun 17 2020 at 13:05)</a>:</h4>
<p>yup, expansion of bodies (and headers, as in <code>const C: ty_macro!() = 92;</code>) should be done lazily I would thing</p>



<a name="201137707"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201137707" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201137707">(Jun 17 2020 at 13:06)</a>:</h4>
<p>Won't we end up doing expansion and parsing of bodies eagerly anyways to collect all impls that could apply to a type?</p>



<a name="201137757"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201137757" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201137757">(Jun 17 2020 at 13:07)</a>:</h4>
<p><span class="user-mention" data-user-id="211727">@Jonas Schievink</span> today, we indeed have to do eager expansion, because impls leak beyond function bodies</p>



<a name="201137873"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201137873" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201137873">(Jun 17 2020 at 13:08)</a>:</h4>
<p>But we plan to deprecate this (to make IDE go faster), so we should try to lazy-ify this. Specifically, the tentative long-term plan is that item body is sort-of like a downstream crate with respect to visibility of things</p>



<a name="201137896"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201137896" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201137896">(Jun 17 2020 at 13:08)</a>:</h4>
<p>Yeah, makes sense to prepare for that I suppose</p>



<a name="201138503"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201138503" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201138503">(Jun 17 2020 at 13:13)</a>:</h4>
<p>Not as much prepare, as to prove that the optimization makes sense (but it seems like it does)</p>



<a name="201138773"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201138773" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201138773">(Jun 17 2020 at 13:16)</a>:</h4>
<p>TBH I think we should act like impls inside function bodies can't affect types outside that body, with the deprecation just making it official that this won't be supported (admittedly it's theoretical currently anyway, since we don't support any kind of impl in function bodies...)</p>



<a name="201138861"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201138861" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201138861">(Jun 17 2020 at 13:16)</a>:</h4>
<p>or in other words, it seems a waste of time to plan to implement support for it if we want to deprecate it anyway</p>



<a name="201139158"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201139158" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201139158">(Jun 17 2020 at 13:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="133169">matklad</span> <a href="#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/ItemTree/near/201137593">said</a>:</p>
<blockquote>
<p>yup, expansion of bodies (and headers, as in <code>const C: ty_macro!() = 92;</code>) should be done lazily I would thing</p>
</blockquote>
<p>How this is currently handled? <code>ast::TypeRef</code> does not have a macro variant</p>



<a name="201139221"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201139221" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201139221">(Jun 17 2020 at 13:20)</a>:</h4>
<p><span class="user-mention" data-user-id="211727">@Jonas Schievink</span> by not doing macro expansion in this postions at all :D</p>



<a name="201139271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201139271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201139271">(Jun 17 2020 at 13:20)</a>:</h4>
<p>... I think it just isn't? (... too late)</p>



<a name="201139293"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201139293" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201139293">(Jun 17 2020 at 13:20)</a>:</h4>
<p>Works for me :D</p>



<a name="201139685"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201139685" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201139685">(Jun 17 2020 at 13:23)</a>:</h4>
<p>I am kind of working on refactoring type lowering (introducing another intermediate representation), which kind of touches on that -- I guess macro expansion would happen during lowering to that new IR</p>



<a name="201146864"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201146864" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201146864">(Jun 17 2020 at 14:16)</a>:</h4>
<p>What happens when expanding a macro call inside an impl or trait? Does r-a support that currently? How does the resulting AST look? The <code>ItemTree</code> assumes that its given a module, but that wouldn't be true here, right?</p>



<a name="201147005"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201147005" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201147005">(Jun 17 2020 at 14:17)</a>:</h4>
<p><span class="user-mention" data-user-id="211727">@Jonas Schievink</span> see <a href="https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_hir_def/src/data.rs#L168-L181">https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/ra_hir_def/src/data.rs#L168-L181</a></p>



<a name="201147215"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201147215" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201147215">(Jun 17 2020 at 14:18)</a>:</h4>
<p>We collect inner items from sources, bypassing raw items</p>



<a name="201147338"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201147338" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201147338">(Jun 17 2020 at 14:19)</a>:</h4>
<p>So we get <code>MacroItems</code>, which is a <code>ModuleItemsOwner</code>, even though we're only looking for associated items, hmm</p>



<a name="201162948"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201162948" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201162948">(Jun 17 2020 at 16:04)</a>:</h4>
<p>Okay, figured out the item data queries. Now on to inner items.</p>



<a name="201163024"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201163024" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201163024">(Jun 17 2020 at 16:04)</a>:</h4>
<p>Wow, literally anything can have inner items.</p>



<a name="201163115"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201163115" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201163115">(Jun 17 2020 at 16:05)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="k">enum</span> <span class="nc">En</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">Variant</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="k">fn</span> <span class="nf">f</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"> </span><span class="mi">0</span><span class="w"> </span><span class="p">},</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="201163254"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201163254" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201163254">(Jun 17 2020 at 16:06)</a>:</h4>
<div class="codehilite"><pre><span></span><code><span class="k">const</span><span class="w"> </span><span class="n">_</span>: <span class="p">[();</span><span class="w"> </span><span class="p">{</span><span class="k">fn</span> <span class="nf">lol</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"> </span><span class="mi">0</span><span class="p">}]</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="p">[];</span><span class="w"></span>
</code></pre></div>



<a name="201163272"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201163272" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201163272">(Jun 17 2020 at 16:06)</a>:</h4>
<p>but yes, your proc_macro_hack version is better :D</p>



<a name="201163405"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201163405" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201163405">(Jun 17 2020 at 16:07)</a>:</h4>
<p>In general, for this reason I am <em>somewhat</em> unhappy that we have a very strict split between expression and item worlds...</p>



<a name="201168091"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201168091" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201168091">(Jun 17 2020 at 16:45)</a>:</h4>
<p>Hmm, seems somewhat problematic to make ItemTree the sole source of items if it <em>also</em> wants to process item bodies lazily. That means that inner items won't have an ID in the tree, but we need one when lowering the body.</p>



<a name="201169316"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201169316" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201169316">(Jun 17 2020 at 16:54)</a>:</h4>
<p>Ah, well, the item tree can eagerly process them as long as it doesn't expand macros</p>



<a name="201169705"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201169705" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201169705">(Jun 17 2020 at 16:58)</a>:</h4>
<p>the way I would imagine it to work is that item bodies get their own item trees, and item IDs are basically concatenated paths through this 'tree of trees' (i.e. a root item ID is simply the index in the root tree, but a nested item ID would be the outer item's ID + the index in that tree)</p>



<a name="201169730"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201169730" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201169730">(Jun 17 2020 at 16:58)</a>:</h4>
<p>but I'm not really up to date on the whole thing <span aria-label="shrug" class="emoji emoji-1f937" role="img" title="shrug">:shrug:</span></p>



<a name="201192472"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201192472" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201192472">(Jun 17 2020 at 19:59)</a>:</h4>
<p>Yup, I imagine this setup as well</p>



<a name="201192600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201192600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201192600">(Jun 17 2020 at 20:00)</a>:</h4>
<p>Okay, that's quite different from what I have</p>



<a name="201192923"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201192923" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201192923">(Jun 17 2020 at 20:02)</a>:</h4>
<p>Ideally, we should be able to swtich impl strategies relatively painless as well...</p>



<a name="201192944"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201192944" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201192944">(Jun 17 2020 at 20:02)</a>:</h4>
<p>But I don't know how to achieve that</p>



<a name="201193001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201193001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201193001">(Jun 17 2020 at 20:03)</a>:</h4>
<p>Well, at least, with the <code>hir</code> layer, one can be relatively sure that no changes to IDE will be required</p>



<a name="201713255"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/ItemTree/near/201713255" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/ItemTree.html#201713255">(Jun 23 2020 at 11:25)</a>:</h4>
<blockquote>
<p>175mb ItemTreeQuery</p>
</blockquote>
<p>Pretty heavy</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>